@Echo off
Echo --------------------------------------------------------------------------------
Echo %~f0 %*

:: File: C:\Documents and Settings\paul\My Documents\Src\Batch\set_GROOVY.cmd
:: Date: 10:56 PM 12/19/2010

:: Requires the current environment to have DelayedExpansion and 
:: CommandExtensions enabled for Current User {HKCU} or Local Machine {HKLM}:
::    reg add "HKCU\Software\Microsoft\Command Processor" /V EnableExtensions  /T REG_DWORD  /d 0x1 /f
::    reg add "HKCU\Software\Microsoft\Command Processor" /V DelayedExpansion  /T REG_DWORD  /d 0x1 /f
    
Set GROOVY_HOME=
Set GROOVYCMD=

If /I "%1" equ "latest" "%~0" 175
Call :ChkGroovy "%~1" Groovy-1.7.5 1.7.5 175  groovy-1.6.9 1.6.9 169  groovy-1.5.8 1.5.8 158

Exit /B

:: ----------------------------------------------------------------------------
:: ----------------------------------------------------------------------------

:: ChkGroovy Params:
::    User-supplied cmd line parm, 
::    triplets of directory/version tags.
::       The first tag of the triplet must be the actual directory name
::       The second and third tags are aliases

:ChkGroovy
Set PARMS=

:ChkGroovyLoop
Set PARMS=!PARMS! %2 or %3 or %4 ;
If /I "%~1" equ "%~2" Set GROOVY_HOME=c:\Program Files\groovy.codehaus.org\%~2
If /I "%~1" equ "%~3" Set GROOVY_HOME=c:\Program Files\groovy.codehaus.org\%~2
If /I "%~1" equ "%~4" Set GROOVY_HOME=c:\Program Files\groovy.codehaus.org\%~2
:: If first tag of next triplet is blank, we are done.
:: If we found a HOME, set stuff dependent on HOME.
If "%~5"=="" (
   If "!GROOVY_HOME!"=="" (
      Echo.
      Echo Looking for a valid GROOVY version:
      Echo !PARMS!
   ) Else (
      Set GROOVYCMD=!GROOVY_HOME!\bin\groovy.exe
      Echo GROOVY_HOME=!GROOVY_HOME!
      Echo GROOVYCMD=!GROOVYCMD!
      "!GROOVYCMD!" --version
   )
   Exit /B
)
:: Keep %1, scroll next triplet into %2 %3 %4
Shift /2
Shift /2
Shift /2 
Goto :ChkGroovyLoop

